home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z8.ADF / Esuom / esuom.c < prev    next >
C/C++ Source or Header  |  1987-07-14  |  4KB  |  161 lines

  1. /* esuom - my first screen hack! */
  2. /* Sean Riddle  7/87 */
  3. /* Based on RKM Vol I, Pg 3-108, input.device IND_ADDHANDLER sample prog */
  4. /* OKC ACE BBS: (405) 631-9040 */
  5.  
  6. #include <intuition/intuition.h>
  7. #include <exec/types.h>
  8. #include <exec/ports.h>
  9. #include <exec/memory.h>
  10. #include <exec/io.h>
  11. #include <exec/tasks.h>
  12. #include <exec/interrupts.h>
  13. #include <devices/input.h>
  14. #include <exec/devices.h>
  15. #include <devices/inputevent.h>
  16.  
  17. struct IntuitionBase *IntuitionBase;
  18. struct IntuiMessage *GetMsg();
  19. struct IntuiMessage *msg;
  20. struct Window *OpenWindow();
  21. struct Window *Window;
  22.  
  23. struct MsgPort *inputDevPort;
  24. struct IOStdReq *inputRequestBlock;
  25. struct Interrupt handlerStuff;
  26.  
  27. extern struct MsgPort *CreatePort();
  28. extern struct IOStdReq *CreateStdIO();
  29.  
  30. struct MemEntry me[10];
  31.  
  32. struct NewWindow nw = {
  33.    50,50,
  34.    73,10,
  35.    -1,-1,
  36.    CLOSEWINDOW,
  37.    WINDOWCLOSE|ACTIVATE|WINDOWDRAG,
  38.    NULL,
  39.    NULL,
  40.    "Esuom",
  41.    NULL,
  42.    NULL,
  43.    0,0,0,0,
  44.    WBENCHSCREEN
  45. };
  46.  
  47. USHORT pointer[]=
  48. {
  49. 0x0000,0x0000,
  50.  
  51. 0x0000,0x0000,
  52. 0x0000,0x0000,
  53. 0x0000,0x0000,
  54. 0x0000,0x0000,
  55. 0x0000,0x0000,
  56. 0x0000,0x0000,
  57. 0x0000,0x0100,
  58. 0x0100,0x0280,
  59. 0x0380,0x0640,
  60. 0x01C0,0x0320,
  61. 0x00E0,0x0196,
  62. 0x0076,0x00C9,
  63. 0x003E,0x0061,
  64. 0x001E,0x0031,
  65. 0x003E,0x0061,
  66. 0x003E,0x007F,
  67. 0x0000,0x003F,
  68. 0x0000,0x0000,
  69.  
  70. 0x0000,0x0000
  71. };
  72.  
  73. void cleanup(); /* must declare since it doesn't return an int */
  74.  
  75. /* my original input handler - too slow, caused stack overflows
  76.    unless stack was approx 100000!
  77.    rewritten in ASM - see InterfaceHandler.asm
  78.  
  79. struct InputEvent *myhandler(ev,mydata)
  80. struct InputEvent *ev;
  81. struct MemEntry *mydata[];
  82. {
  83.    if(ev->ie_Class==IECLASS_RAWMOUSE) {
  84.       ev->ie_X=-ev->ie_X;
  85.       ev->ie_Y=-ev->ie_Y;
  86.       if(ev->ie_Code==IECODE_LBUTTON)
  87.          ev->ie_Code=IECODE_RBUTTON;
  88.       else if(ev->ie_Code==IECODE_RBUTTON)
  89.          ev->ie_Code=IECODE_LBUTTON;
  90.       if(ev->ie_Code==IECODE_RBUTTON+IECODE_UP_PREFIX)
  91.          ev->ie_Code=IECODE_LBUTTON+IECODE_UP_PREFIX;
  92.       else if(ev->ie_Code==IECODE_LBUTTON+IECODE_UP_PREFIX)
  93.          ev->ie_Code=IECODE_RBUTTON+IECODE_UP_PREFIX;
  94.    }
  95.    return(ev);
  96. }
  97. */
  98.  
  99. extern VOID HandlerInterface(); /* our input handler */
  100.  
  101. void main(argc,argv)
  102. int argc;
  103. char *argv;
  104. {
  105.    ULONG class;
  106.  
  107.    printf("Esuom - 7/15/87 by Sean Riddle - OKC ACE BBS (405) 631-9040\n");
  108.    if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  109.       cleanup("Intuitionless.");
  110.    if(!(Window=(struct Window *)OpenWindow(&nw)))
  111.       cleanup("Window stuck.");
  112.    SetPointer(Window,pointer,18,16,-15,-14);
  113.    if(!(inputDevPort=CreatePort(0,0)))
  114.       cleanup("No port in sight.");
  115.    if(!(inputRequestBlock=CreateStdIO(inputDevPort)))
  116.       cleanup("IO not created.");
  117.    handlerStuff.is_Data=(APTR)&me[0];
  118.    handlerStuff.is_Code=HandlerInterface;
  119.    handlerStuff.is_Node.ln_Pri=51;  /* puts handler before Intuition() */
  120.    if(OpenDevice("input.device",0,inputRequestBlock,0))
  121.       cleanup("No input.device.");
  122.    inputRequestBlock->io_Command=IND_ADDHANDLER;
  123.    inputRequestBlock->io_Data=(APTR)&handlerStuff;
  124.    DoIO(inputRequestBlock);
  125.    for(;;) {
  126.       Wait(1<<Window->UserPort->mp_SigBit);
  127.       if(msg=(struct IntuiMessage *)GetMsg(Window->UserPort)) {
  128.          class=msg->Class;
  129.          ReplyMsg(msg);
  130.          if(class==CLOSEWINDOW)
  131.             break;
  132.       }
  133.    }
  134.    inputRequestBlock->io_Command=IND_REMHANDLER;
  135.    inputRequestBlock->io_Data=(APTR)&handlerStuff;
  136.    DoIO(inputRequestBlock);
  137.    cleanup("Mouse interface corrected....");
  138. }
  139.  
  140. void cleanup(text) /* get rid of everything we've gotten */
  141. char *text;
  142. {
  143.    printf("%s\n",text);
  144.  
  145.    if(inputRequestBlock) {
  146.       if (inputRequestBlock->io_Device)
  147.          CloseDevice(inputRequestBlock);
  148.       DeleteStdIO(inputRequestBlock);
  149.    }
  150.    if(inputDevPort)
  151.       DeletePort(inputDevPort);
  152.    if(Window) {
  153.       ClearPointer(Window);
  154.       CloseWindow(Window);
  155.    }
  156.    if(IntuitionBase)
  157.       CloseLibrary(IntuitionBase);
  158.    exit(0);
  159. }
  160.  
  161.